package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserExperience;
import com.happy.cat.project.system.service.IUserExperienceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户经验明细Controller
 *
 * @author verne
 * @date 2020-08-12
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userExperience" )
@Api("用户经验明细 API")
public class UserExperienceController extends BaseController {

    private final IUserExperienceService iUserExperienceService;

    /**
     * 查询用户经验明细列表
     */
    @ApiOperation(value = "查询用户经验明细列表",notes = "查询用户经验明细列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userExperience:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserExperience userExperience)
    {
        startPage();
        LambdaQueryWrapper<UserExperience> lqw = new LambdaQueryWrapper<UserExperience>();
        if (userExperience.getSource() != null){
            lqw.eq(UserExperience::getSource ,userExperience.getSource());
        }
        if (userExperience.getAccountId() != null){
            lqw.eq(UserExperience::getAccountId ,userExperience.getAccountId());
        }
        if (userExperience.getExperiencePoints() != null){
            lqw.eq(UserExperience::getExperiencePoints ,userExperience.getExperiencePoints());
        }
        if (userExperience.getCurrentExperience() != null){
            lqw.eq(UserExperience::getCurrentExperience ,userExperience.getCurrentExperience());
        }
        if (StringUtils.isNotBlank(userExperience.getRemarks())){
            lqw.eq(UserExperience::getRemarks ,userExperience.getRemarks());
        }
        List<UserExperience> list = iUserExperienceService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户经验明细列表
     */
    @ApiOperation(value = "导出用户经验明细列表",notes = "导出用户经验明细列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userExperience:export')" )
    @Log(title = "用户经验明细" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserExperience userExperience) {
        LambdaQueryWrapper<UserExperience> lqw = new LambdaQueryWrapper<UserExperience>(userExperience);
        List<UserExperience> list = iUserExperienceService.list(lqw);
        ExcelUtil<UserExperience> util = new ExcelUtil<UserExperience>(UserExperience. class);
        return util.exportExcel(list, "userExperience" );
    }

    /**
     * 获取用户经验明细详细信息
     */
    @ApiOperation(value = "获取用户经验明细详细信息",notes = "获取用户经验明细详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userExperience:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserExperienceService.getById(id));
    }

    /**
     * 新增用户经验明细
     */
    @ApiOperation(value = "新增用户经验明细",notes = "新增用户经验明细",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userExperience:add')" )
    @Log(title = "用户经验明细" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserExperience userExperience) {
        return toAjax(iUserExperienceService.save(userExperience) ? 1 : 0);
    }

    /**
     * 修改用户经验明细
     */
    @ApiOperation(value = "修改用户经验明细",notes = "修改用户经验明细",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userExperience:edit')" )
    @Log(title = "用户经验明细" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserExperience userExperience) {
        return toAjax(iUserExperienceService.updateById(userExperience) ? 1 : 0);
    }

    /**
     * 删除用户经验明细
     */
    @ApiOperation(value = "删除用户经验明细",notes = "删除用户经验明细",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userExperience:remove')" )
    @Log(title = "用户经验明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserExperienceService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
